//
//  PortalViewController.m
//  Aun
//
//  Created by Alexander on 8/24/10.
//  Copyright 2010 KTH Royal Institute of Technology. All rights reserved.
//

#import <QuartzCore/QuartzCore.h>
#import "PortalViewController.h"
#import "TimelineCell.h"
#import "Patient.h"

@implementation PortalViewController

@synthesize patient;
@synthesize cell;
@synthesize photoImageView;
@synthesize fullXmlButton;
@synthesize patientInfoTextView;
@synthesize bubbleTextView;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	[[fullXmlButton layer] setCornerRadius:8.0f];
	[[fullXmlButton layer] setMasksToBounds:YES];
	[[fullXmlButton layer] setBorderWidth:1.0f];
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

- (void)viewWillAppear:(BOOL)animated {
	[[cell infoLabel] setText:[patient name]];
	[photoImageView setImage:[patient photo]];
	NSString *g = [[NSString alloc] initWithFormat:@"%@\n\n%@\n\n%@\n\n%@", [patient patientSummary], [patient questionsForConsensusMeeting], [patient previousDecisions], [patient finishedAndOngoingTreatments]];
	[patientInfoTextView setText:g];
	[g release];
	[bubbleTextView setText:[patient bubbleText]];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 150;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	if (cell == nil) {
		NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TimelineCell" owner:self options:nil];
		cell = [nib objectAtIndex:0];
	}
	[self viewWillAppear:YES]; // cheat to set all fields, can be separated out to method
	
	return cell;
}


@end
